import {
    Action,
    IfElse,
    LatchedSequence,
    rc,
    ResultCode,
    Selector,
} from "@konghayao/blueshell";
import { BaseEnemy } from "./Base";
type Event = Function;
class NormalAttack extends Action<BaseEnemy, Event> {
    protected onEvent(state: BaseEnemy, event: Function): ResultCode {
        state.attack();
        return rc.RUNNING;
    }
}
class RandomPatrol extends Action<BaseEnemy, Event> {
    protected onEvent(state: BaseEnemy, event: Function): ResultCode {
        return state.patrol() ? rc.RUNNING : rc.FAILURE;
    }
}
class NormalDefense extends Action<BaseEnemy, Event> {
    protected onEvent(state: BaseEnemy, event: Function): ResultCode {
        state.defense();
        return rc.RUNNING;
    }
}
class Escape extends Action<BaseEnemy, Event> {
    protected onEvent(state: BaseEnemy, event: Function): ResultCode {
        state.escape();
        return rc.RUNNING;
    }
}
const attackTree = () => new LatchedSequence("attack", [new NormalAttack()]);
const patrolTree = () =>
    new IfElse("isFindPlayer", (state) => state.isAngry, new RandomPatrol());
const defenseTree = () =>
    new IfElse(
        "isFindPlayer",
        (state) => state.HP < 20,
        new NormalDefense(),
        new Escape()
    );

export function createBaseTree() {
    return new Selector("base", [patrolTree(), attackTree(), defenseTree()]);
}
